
function Animator(fps,timeout,formule){
	this.fps = fps||30;
	this.timeout = timeout||false;
	if(arguments.length > 2){
		arguments.slice = Array.prototype.slice;
		this.args = arguments.slice(2);
	}
	this.time = this.fps/1000;
}

Animator.prototype = {
	constructor:Animator,
	fps:0,
	time:0,
	count:0,
	paused:true,
	TimeoutID:-1,
	IntervalID:-1,
	formule:function(){},
	parse_re:/^([\d.]+)([a-z]*)$/,
	
	onLoop:function(){},
	onStart:function(){},
	onFinish:function(){},
	
	run:function(){
		if(!this.paused)return false;
		if(this.onStart.apply(this,this.args)==false)return false;
		
		function interval(){
			var o = arguments.callee.$;
			o.count++;
			o.onLoop.apply(o,o.args);
		}
		interval.$ = this;
		this.IntervalID = window.setInterval(interval, this.time);
		
		if(this.timeout){
			function timeout(){
				var o = arguments.callee.$;
				o.stop();
				window.clearTimeout(o.TimeoutID);
				o.TimeoutID=-1;
			}
			timeout.$ = this;
			this.TimeoutID = window.setTimeout(this.timeout);
		}
		this.paused=false;
		
	},
	stop:function(){
		this.paused=true;
		if(this.onFinish.apply(this,this.args)!=false){
			window.clearInterval(this.IntervalID);
		}
		this.IntervalID=-1;
	},
	toString:function(){
		return "Animator [fps:"+this.fps+", time:"+(this.count*this.time)+"]";
	}
}



/*

function Effects(target,config,formula){
	
}

Effects.Formules={
	Easing:function(current,target,delay){
		//v += ( vf - va ) / d
		return (current + (target - current) / delay);
	},
	Elastic:function(current,target,fricction,ratio){
		//v += (vt = vt * f + (vf - va) * r)

		var f=arguments.callee;
		return current + (f.z = ((f.z||0) * fricction + (current - target) * ratio));
	}
}
			
*/